﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Entity;
using DataControls;

namespace GiaoVien_QuanLy_DeTai
{
    public partial class THAMSO_Form : Form
    {
        THAMSO thamso = new THAMSO();
        public THAMSO_Form()
        {
            InitializeComponent();
        }

        private void THAMSO_Form_Load(object sender, EventArgs e)
        {
            txtGiaTri.Text = "";
            txtTenThamSo.Text = "";
        }

        private void btnHienThi_Click(object sender, EventArgs e)
        {
            thamso.hienthi_ThamSo(dtgThamSo);
        }

        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            if (txtTenThamSo.Text == "")
            {
                MessageBox.Show("Ban Chua Nhap Ten Tham So");
                txtTenThamSo.Focus();
                return;
            }
            else if (txtGiaTri.Text == "")
            {
                MessageBox.Show("Ban chua nhap gia tri");
                txtGiaTri.Focus();
                return;
            }
            else
            {
                thamso.tenThamSo = txtTenThamSo.Text.ToString();
                try
                {
                    if ((thamso.giatri = (float)Convert.ToDouble(txtGiaTri.Text)) <= 0)
                    {
                        MessageBox.Show("ban chua nhap dung");
                        txtGiaTri.Focus();
                        return;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("ban chua nhap dung du lieu\n" + ex.Message);
                }
                thamso.capnhat_ThamSo(thamso);

                txtGiaTri.Text = "";
                txtTenThamSo.Text = "";
                thamso.hienthi_ThamSo(dtgThamSo);
            }
        }

        private void dtgThamSo_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            dtgThamSo.AllowUserToAddRows = false;
            int dong = e.RowIndex;
            txtTenThamSo.Text = dtgThamSo.Rows[dong].Cells[0].Value.ToString();
            txtGiaTri.Text = dtgThamSo.Rows[dong].Cells[1].Value.ToString();
        }


       
    }
}
